package zjut.cocouml.editpolicy;

import java.util.Map;

import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.AbstractEditPolicy;

import zjut.cocouml.command.BMethodModifyCommand;
import zjut.cocouml.model.BMethod;

public class ModifyMethodPolicy extends AbstractEditPolicy{
	
	public Command getCommand(Request request) {
		
		if (request.getType().equals("modifyMethod")) {
			System.out.println("ModifyMethodPolicy...getCommand.." + request);
			return createModifyMethodCommand(request);
		}
		return null;
	}

	private Command createModifyMethodCommand(Request request) {
		BMethodModifyCommand command = new BMethodModifyCommand();
		command.setModel((BMethod)getHost().getModel());
		
		Map map = request.getExtendedData();
		command.setNewMethodName((String)map.get("name"));
		command.setNewAccessAuthrity((String)map.get("accessAuthrity"));
		command.setNewParamters((String)map.get("paramters"));
		command.setNewType((String)map.get("type"));
		command.setNewFinal((Boolean)map.get("isFinal"));
		command.setNewStatic((Boolean)map.get("isStatic"));
		command.setNewAbstract((Boolean)map.get("isAbstract"));
		
		return command;
	}
}
